package com.communal.service.impl.tarif;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.communal.dao.ICommunalDao;
import com.communal.model.Model;
import com.communal.model.tarif.Tarif;
import com.communal.service.impl.AbstractService;
import com.communal.util.AppException;

/**
 * 
 * @author Created by andrey.kuznetsov <br>
 * @author Last modified by $Author$ <br>
 * @author Last modified on $Date$ at revision $Revision$ <br>
 */
@Service
public class TarifService extends AbstractService{

	@Autowired
	ICommunalDao communalDao;
	
	@SuppressWarnings("rawtypes")
	protected void validateTarifName(Model p_model, Class p_class, String p_tarifName) throws AppException {
		if(StringUtils.isBlank( p_tarifName )){
			throw new AppException(messageSource.getMessage("message.error.tarif.empty.name", null, null));
		}
		List<Tarif> tarifs = communalDao.getEnabledTarifsByName( p_model, p_class, p_tarifName );
		if(CollectionUtils.isNotEmpty( tarifs )){
			throw new AppException(messageSource.getMessage("message.error.tarif.exist", null, null));
		}
	}
}
